home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SNNSV32.ZIP / SNNSv3.2 / kernel / sources / update_f.c < prev    next >
C/C++ Source or Header  |  1994-04-25  |  62KB  |  2,138 lines

  1. /*****************************************************************************
  2.   FILE           : update_f.c
  3.   SHORTNAME      : 
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : SNNS-Kernel Network Update Functions
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Niels Mache
  10.   DATE           : 18.03.91
  11.  
  12.   CHANGED BY     : Sven Doering, Michael Vogt (Martin Reczko)
  13.   IDENTIFICATION : @(#)update_f.c    1.21 3/15/94
  14.   SCCS VERSION   : 1.21
  15.   LAST CHANGE    : 3/15/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.  
  19. ******************************************************************************/
  20. #include <stdio.h>
  21. #include <math.h>
  22. #include <values.h>
  23.  
  24. #include "kr_typ.h"     /*  Kernel Types and Constants  */
  25. #include "kr_const.h"     /*  Constant Declarators for SNNS-Kernel  */
  26. #include "kr_def.h"     /*  Default Values  */
  27. #include "kernel.h"     /*  Kernel Functions  */
  28. #include "glob_typ.h"
  29. #include "kr_ui.h"
  30. #include "kr_mem.h"     /*  Memory Manager Functions  */
  31. #include "random.h"     /*  Randomize Library Function Prototypes  */
  32. #include "kr_mac.h"     /*  Kernel Macros   */
  33. #include "krart_df.h"    /*  Macros and Definitions for ART */
  34. #include "kr_art1.h"
  35. #include "kr_art2.h"
  36. #include "kr_amap.h"
  37. #include "kr_art.h"      /*  Function Prototypes of ART kernel functions */
  38. #include "kr_td.h"       /*  Function Prototypes of Time Delay functions */
  39. #include "rcc_learn.h"
  40. #include "cc_rcc.h"
  41. #include "cc_mac.h"
  42. #include "dlvq_learn.h"
  43. #include "update_f.ph"
  44. #include "kr_JordElm.h"
  45. #include "func_mac.h" 
  46.  
  47. /*#################################################
  48.  
  49. GROUP: Update Functions
  50.  
  51. #################################################*/
  52.  
  53. /*****************************************************************************
  54.   FUNCTION : UPDATE_syncPropagate
  55.  
  56.   PURPOSE  : synchronous propagation
  57.   RETURNS  : 
  58.   NOTES    :
  59.  
  60.   UPDATE   : 01.12.93
  61. ******************************************************************************/
  62. krui_err  UPDATE_syncPropagate(float *parameterArray, int NoOfParams)
  63. {
  64.     register struct Unit   *unit_ptr;
  65.  
  66.  
  67.     /*    update unit activations first  */
  68.     FOR_ALL_UNITS( unit_ptr )
  69.     if ( !IS_INPUT_UNIT( unit_ptr) && UNIT_IN_USE( unit_ptr ))
  70.         /*  unit isn't an input unit and is in use and enabled  */
  71.         unit_ptr->act = (*unit_ptr->act_func) (unit_ptr);
  72.  
  73.     /*    update unit outputs */
  74.     FOR_ALL_UNITS( unit_ptr )
  75.     if UNIT_IN_USE( unit_ptr )
  76.         /*  unit is in use and enabled  */
  77.         if (unit_ptr->out_func == OUT_IDENTITY)
  78.         /*  identity output function: don't call the output function  */
  79.         unit_ptr->Out.output = unit_ptr->act;
  80.         else
  81.         /* no identity output function: calculate unit's output also  */
  82.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  83.  
  84.     return( KRERR_NO_ERROR );
  85. }
  86.  
  87.  
  88.  
  89. /*****************************************************************************
  90.   FUNCTION : UPDATE_serialPropagate
  91.  
  92.   PURPOSE  :  serial propagation
  93.   RETURNS  : 
  94.   NOTES    :
  95.  
  96.   UPDATE   : 01.12.93
  97. ******************************************************************************/
  98. krui_err  UPDATE_serialPropagate(float *parameterArray, int NoOfParams)
  99. {
  100.     register struct Unit   *unit_ptr;
  101.  
  102.  
  103.     /*    update unit activations and outputs */
  104.     FOR_ALL_UNITS( unit_ptr )
  105.     if UNIT_IN_USE( unit_ptr ){
  106.         /*  unit is in use and enabled  */
  107.         if (!IS_INPUT_UNIT( unit_ptr ))
  108.         /*  this isn't a input unit: calculate the activation of 
  109.             the unit by calling the activation function   */
  110.         unit_ptr->act = (*unit_ptr->act_func) (unit_ptr);
  111.  
  112.         if (unit_ptr->out_func == OUT_IDENTITY)
  113.         /*  identity output function: don't call the output function */
  114.         unit_ptr->Out.output = unit_ptr->act;
  115.         else
  116.         /*  no identity output function: calculate unit's output also */
  117.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  118.     }
  119.  
  120.     return( KRERR_NO_ERROR );
  121. }
  122.  
  123.  
  124.  
  125. /*****************************************************************************
  126.   FUNCTION : UPDATE_randomOrderPropagate
  127.  
  128.   PURPOSE  : random order propagation
  129.   RETURNS  : 
  130.   NOTES    :
  131.  
  132.   UPDATE   : 
  133. ******************************************************************************/
  134. krui_err  UPDATE_randomOrderPropagate(float *parameterArray, int NoOfParams)
  135. {
  136.     register struct Unit   *unit_ptr, *u_array;
  137.     register int   no_of_units;
  138.     int   n;
  139.  
  140.  
  141.     u_array = unit_array;
  142.     no_of_units = NoOfUnits;
  143.  
  144.     for (n = 0; n < no_of_units; n++){
  145.     /*      choose unit  */
  146.     unit_ptr = u_array + (1 + lrand48() % no_of_units);
  147.  
  148.     if (!IS_INPUT_UNIT( unit_ptr ))
  149.         /*  this isn't a input unit: calculate the activation of the unit by
  150.         calling the activation function */
  151.         unit_ptr->act = (*unit_ptr->act_func) (unit_ptr);
  152.  
  153.     if (unit_ptr->out_func == OUT_IDENTITY)
  154.         /*  identity output function: don't call the output function  */
  155.         unit_ptr->Out.output = unit_ptr->act;
  156.     else
  157.         /*  no identity output function: calculate unit's output also  */
  158.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  159.     }
  160.  
  161.     return( KRERR_NO_ERROR );
  162. }
  163.  
  164.  
  165.  
  166. /*****************************************************************************
  167.   FUNCTION : UPDATE_randomPermutPropagate
  168.  
  169.   PURPOSE  : random permutation propagation
  170.   RETURNS  : 
  171.   NOTES    :
  172.  
  173.   UPDATE   : 
  174. ******************************************************************************/
  175. krui_err  UPDATE_randomPermutPropagate(float *parameterArray, int NoOfParams)
  176. {
  177.     register struct Unit     *unit_ptr;
  178.     register TopoPtrArray  topo_ptr;
  179.     int  ret_code;
  180.  
  181.  
  182.     if (NetModified || (TopoSortID != PERMUTATION)){
  183.     /*  networt was modified or permutation array isn't initialized  */
  184.     ret_code = kr_makeUnitPermutation();
  185.     if (ret_code != KRERR_NO_ERROR)
  186.         return( ret_code );
  187.     }
  188.  
  189.     topo_ptr = topo_ptr_array;
  190.  
  191.     /*  propagate net  */
  192.     while ((unit_ptr = *++topo_ptr) != NULL){
  193.     if (!IS_INPUT_UNIT( unit_ptr ))
  194.         /*  this isn't a input unit: calculate the activation of the unit
  195.         by calling the activation function */
  196.         unit_ptr->act = (*unit_ptr->act_func) (unit_ptr);
  197.  
  198.     if (unit_ptr->out_func == OUT_IDENTITY)
  199.         /*  identity output function: don't call the output function  */
  200.         unit_ptr->Out.output = unit_ptr->act;
  201.     else
  202.         /*  no identity output function: calculate unit's output also  */
  203.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  204.     }
  205.  
  206.     return( KRERR_NO_ERROR );
  207. }
  208.  
  209.  
  210.  
  211. /*****************************************************************************
  212.   FUNCTION : UPDATE_topologicalPropagate
  213.  
  214.   PURPOSE  : Propagate Units in topological order
  215.   RETURNS  : 
  216.   NOTES    :
  217.  
  218.   UPDATE   : 
  219. ******************************************************************************/
  220. krui_err  UPDATE_topologicalPropagate(float *parameterArray, int NoOfParams)
  221. {
  222.     register struct Unit  *unit_ptr;
  223.     register TopoPtrArray  topo_ptr;
  224.     int  ret_code;
  225.  
  226.  
  227.     if (NetModified || (TopoSortID != TOPOLOGICAL_FF)){
  228.     /*  networt was modified or topologic array isn't initialized  */
  229.     ret_code = kr_topoSort( TOPOLOGICAL_FF );
  230.     if (ret_code != KRERR_NO_ERROR)
  231.         return( ret_code );
  232.  
  233.     NetModified = FALSE;
  234.     }
  235.  
  236.  
  237.     topo_ptr = topo_ptr_array + 1;
  238.  
  239.     /*  propagate input units only  */
  240.     while ((unit_ptr = *topo_ptr++) != NULL){
  241.     /*  input units, don't call the activation function  */
  242.  
  243.     if (unit_ptr->out_func == OUT_IDENTITY)
  244.         /*  identity output function: don't call the output function  */
  245.         unit_ptr->Out.output = unit_ptr->act;
  246.     else
  247.         /*  no identity output function: calculate unit's output also  */
  248.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  249.     }
  250.  
  251.     /*  propagate hidden units only  */
  252.     while ((unit_ptr = *topo_ptr++) != NULL){
  253.     unit_ptr->act = (*unit_ptr->act_func) (unit_ptr);
  254.  
  255.     if (unit_ptr->out_func == OUT_IDENTITY)
  256.         /*  identity output function: don't call the output function  */
  257.         unit_ptr->Out.output = unit_ptr->act;
  258.     else
  259.         /*  no identity output function: calculate unit's output also  */
  260.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  261.     }
  262.  
  263.     /*  propagate output units only  */
  264.     while ((unit_ptr = *topo_ptr++) != NULL){
  265.     unit_ptr->act = (*unit_ptr->act_func) (unit_ptr);
  266.  
  267.     if (unit_ptr->out_func == OUT_IDENTITY)
  268.         /*  identity output function: don't call the output function  */
  269.         unit_ptr->Out.output = unit_ptr->act;
  270.     else
  271.         /*  no identity output function: calculate unit's output also  */
  272.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  273.     }
  274.  
  275.     return( KRERR_NO_ERROR );
  276. }
  277.  
  278.  
  279.  
  280. /*****************************************************************************
  281.   FUNCTION : UPDATE_KohonenPropagate
  282.  
  283.   PURPOSE  : Propagate Units in topological order for Kohonen networks
  284.   RETURNS  : 
  285.   NOTES    :
  286.  
  287.   UPDATE   : 
  288. ******************************************************************************/
  289. krui_err  UPDATE_KohonenPropagate(float *parameterArray, int NoOfParams)
  290. {
  291.     register struct Unit  *unit_ptr;
  292.     register TopoPtrArray  topo_ptr;
  293.     int  ret_code;
  294.  
  295.  
  296.     if (NetModified || (TopoSortID != TOPOLOGIC_TYPE)){
  297.     /*  networt was modified or topologic array isn't initialized  */
  298.     ret_code = kr_topoSort( TOPOLOGIC_TYPE );
  299.     if (ret_code = KRERR_NO_OUTPUT_UNITS) ret_code = KRERR_NO_ERROR;
  300.     if (ret_code != KRERR_NO_ERROR)
  301.         return( ret_code );
  302.  
  303.     NetModified = FALSE;
  304.     }
  305.  
  306.  
  307.     topo_ptr = topo_ptr_array + 1;
  308.  
  309.     /*  propagate input units only  */
  310.     while ((unit_ptr = *topo_ptr++) != NULL){
  311.     if (unit_ptr->out_func == OUT_IDENTITY)
  312.         unit_ptr->Out.output = unit_ptr->act;
  313.     else
  314.         /*  no identity output function: calculate unit's output also  */
  315.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  316.     }
  317.  
  318.     /*  propagate hidden units only  */
  319.     while ((unit_ptr = *topo_ptr++) != NULL){
  320.     unit_ptr->act = (*unit_ptr->act_func) (unit_ptr);
  321.  
  322.     if (unit_ptr->out_func == OUT_IDENTITY)
  323.         unit_ptr->Out.output = unit_ptr->act;
  324.     else
  325.         /*  no identity output function: calculate unit's output also  */
  326.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  327.     }
  328.     return( KRERR_NO_ERROR );
  329. }
  330.  
  331.  
  332.  
  333. /*****************************************************************************
  334.   FUNCTION : normalize_inputvector
  335.  
  336.   PURPOSE  : normalize input vector for Counterpropagation Update Function
  337.   RETURNS  :  
  338.   NOTES    :
  339.  
  340.   UPDATE   : 
  341. ******************************************************************************/
  342. static void normalize_inputvector(float sum)
  343. {
  344.     register struct Unit *unit_ptr;
  345.     register float amount;
  346.  
  347.  
  348.     amount = 1.0 / sqrt( sum );
  349.  
  350.     FOR_ALL_UNITS( unit_ptr )
  351.     if (IS_INPUT_UNIT( unit_ptr ) && UNIT_IN_USE( unit_ptr ))
  352.         /* this is a input unit */
  353.         unit_ptr->Out.output = unit_ptr->Out.output * amount;
  354. }  
  355.  
  356.  
  357.  
  358. /*****************************************************************************
  359.   FUNCTION : UPDATE_CPNPropagate
  360.  
  361.   PURPOSE  : Counterpropagation Update Function
  362.   RETURNS  :  
  363.   NOTES    :
  364.  
  365.   UPDATE   : 
  366. ******************************************************************************/
  367. krui_err  UPDATE_CPNPropagate(float *parameterArray, int NoOfParams)
  368. {
  369.     register struct Unit   *unit_ptr, *winner_ptr;
  370.     register struct Site   *site_ptr;
  371.     register struct Link   *link_ptr;
  372.     register TopoPtrArray  topo_ptr;
  373.  
  374.     float maximum, unit_ptr_net, sum; 
  375.     int  ret_code;
  376.  
  377.  
  378.     if (NetModified || (TopoSortID != TOPOLOGIC_TYPE)){
  379.     /*  networt was modified or topologic array isn't initialized  */
  380.     ret_code = kr_topoSort( TOPOLOGIC_TYPE );
  381.     if (ret_code != KRERR_NO_ERROR)
  382.         return( ret_code );
  383.  
  384.     NetModified = FALSE;
  385.     }
  386.  
  387.     topo_ptr = topo_ptr_array;
  388.     sum = 0.0;
  389.  
  390.     /*  propagagate all input units  */
  391.     while ((unit_ptr = *++topo_ptr) != NULL){
  392.     /*  this is an input unit     */
  393.     unit_ptr->Out.output = unit_ptr->act;
  394.     sum += unit_ptr->Out.output * unit_ptr->Out.output;
  395.     }
  396.   
  397.     if (sum != 0.0)
  398.     /* normalize the inputvector */
  399.     normalize_inputvector( sum );
  400.  
  401.  
  402.     /* propagate Kohonen Layer */
  403.  
  404.     /* calculate the activation and the output values 
  405.        of the hidden units (Kohonen Layer) */
  406.  
  407.     winner_ptr = NULL;
  408.     maximum = -1.0e30;        /* contains the maximum of the activations */
  409.  
  410.     /*  propagagate all hidden units  */
  411.     while ((unit_ptr = *++topo_ptr) != NULL){
  412.     /* this is a hidden unit */
  413.     unit_ptr_net = 0.0;
  414.  
  415.     if (unit_ptr->flags & UFLAG_SITES){
  416.         /* the unit has sites */
  417.         FOR_ALL_SITES_AND_LINKS( unit_ptr, site_ptr, link_ptr )
  418.         unit_ptr_net += (link_ptr->weight * link_ptr->to->Out.output);
  419.     }else{            /* the unit has direct links */
  420.         FOR_ALL_LINKS( unit_ptr, link_ptr )
  421.         unit_ptr_net += (link_ptr->weight * link_ptr->to->Out.output);
  422.     }
  423.  
  424.     if (maximum < unit_ptr_net){ /*  determine winner unit  */
  425.         winner_ptr = unit_ptr;
  426.         maximum = unit_ptr_net;
  427.     }
  428.  
  429.     /* reset output and activation of hidden units  */
  430.     unit_ptr->Out.output = unit_ptr->act = (FlintType) 0;
  431.     }
  432.  
  433.     /* the competitive winner is chosen */
  434.     winner_ptr->Out.output = winner_ptr->act = (FlintType) 1;
  435.  
  436.  
  437.     /* propagate the Grossberg Layer */
  438.  
  439.     /*  propagagate all output units  */
  440.     while ((unit_ptr = *++topo_ptr) != NULL){ /* this is a output unit */
  441.     /* the activation function is the identity function ( weighted sum) */
  442.     unit_ptr->Out.output = unit_ptr->act = (*unit_ptr->act_func) (unit_ptr);
  443.     }
  444.  
  445.     return( KRERR_NO_ERROR );
  446. }
  447.  
  448.  
  449.  
  450. /*****************************************************************************
  451.   FUNCTION : UPDATE_TimeDelayPropagate
  452.  
  453.   PURPOSE  :
  454.   RETURNS  : 
  455.   NOTES    :
  456.  
  457.   UPDATE   : 
  458. ******************************************************************************/
  459. krui_err  UPDATE_TimeDelayPropagate(float parameterArray[], int NoOfParams )
  460. {
  461.     register struct Unit    *unit_ptr;
  462.     register TopoPtrArray   topo_ptr;
  463.     int                     ret_code;
  464.  
  465.     /* initialization if necessary */
  466.     if (NetModified || (TopoSortID != TOPOLOGIC_LOGICAL)){
  467.  
  468.     /*  Net has been modified or topologic array isn't initialized */
  469.     /*  check the topology of the network  */
  470.     /* first: save the logical layer numbers, restore them after check */
  471.     FOR_ALL_UNITS(unit_ptr)
  472.         unit_ptr -> Aux.int_no = unit_ptr -> lln;
  473.     ret_code = kr_topoCheck();
  474.     FOR_ALL_UNITS(unit_ptr)
  475.         unit_ptr -> lln = unit_ptr -> Aux.int_no;
  476.     if (ret_code < KRERR_NO_ERROR)  
  477.         return( ret_code );    /*  an error has occured  */
  478.     if (ret_code < 2)  
  479.         return( KRERR_NET_DEPTH ); /*  the network has less then 2 layers  */
  480.  
  481.     /*  count the no. of I/O units and check the patterns  */
  482.     ret_code = kr_IOCheck();
  483.     if (ret_code < KRERR_NO_ERROR)  return( ret_code );
  484.  
  485.     ret_code = kr_topoSort( TOPOLOGIC_LOGICAL );
  486.     if ((ret_code != KRERR_NO_ERROR) && (ret_code != KRERR_DEAD_UNITS))
  487.         return( ret_code );
  488.  
  489.     NetModified = FALSE;
  490.     }
  491.  
  492.     topo_ptr = topo_ptr_array;
  493.     unit_ptr = *++topo_ptr;
  494.  
  495.     /*  propagate input units only  */
  496.     while (unit_ptr != (struct Unit *) NULL){
  497.     /* input units doesn't have inputs, so don't call the 
  498.        activation function */
  499.  
  500.     if (unit_ptr->out_func == OUT_IDENTITY)
  501.         /*  identity output function: there is no need to call the 
  502.         output function  */
  503.         unit_ptr->Out.output = unit_ptr->act;
  504.     else
  505.         /*  no identity output function: calculate unit's output also  */
  506.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  507.     unit_ptr = *++topo_ptr;
  508.     }
  509.  
  510.     /* use the propagation function of the learning function for the update */
  511.     /* This way, the necessary time delay code is present only once */
  512.     /* Use the special pattern_no -1, to prevent loading of a pattern */
  513.     propagateTDNetForward(-1,-1);
  514.  
  515.     return (KRERR_NO_ERROR);  
  516.  
  517. } /* UPDATE_TimeDelayPropagate */
  518.  
  519.  
  520.  
  521.  
  522.  
  523. /*****************************************************************************
  524.   FUNCTION : UPDATE_ART1_syncPropagate
  525.  
  526.   PURPOSE  : ART 1 update function which does exactly the same as the normal
  527.              synchronous propagate function except that additionally the winner
  528.          of the ART 1 recognition layer is calculated.
  529.   RETURNS  : 
  530.   NOTES    :
  531.  
  532.   UPDATE   : 
  533. ******************************************************************************/
  534. krui_err  UPDATE_ART1_syncPropagate(float *parameterArray, int NoOfParams)
  535. {
  536.     krui_err     ret_code      = KRERR_NO_ERROR;
  537.  
  538.     int          i;
  539.     struct Unit  *winner_ptr; /* recognition unit which is the winner of w.t.a*/
  540.     struct Unit  *unit_ptr;
  541.     TopoPtrArray topo_layer[6];    /* topo_layer[0] : *first input unit
  542.                    topo_layer[1] : *first comp. unit
  543.                    topo_layer[2] : *first rec.  unit
  544.                    topo_layer[3] : *first delay unit
  545.                    topo_layer[4] : *first local reset unit
  546.                    topo_layer[5] : *first special unit
  547.                    (classified_unit)*/
  548.     TopoPtrArray topo_ptr;
  549.     static float rho;
  550.     bool         inp_pat_changed   = FALSE;
  551.     bool         rho_has_changed   = FALSE;
  552.  
  553.  
  554.     /* Check vigilance parameter */
  555.  
  556.     if (NoOfParams < 1) {
  557.     ret_code = KRERR_PARAMETERS;
  558.     return (ret_code);
  559.     } /*if*/
  560.  
  561.     /* Check if rho has changed from last to actual call of this update function
  562.        If rho has changed, then put new activation value into unit rho */
  563.     if (rho != parameterArray[0]) {
  564.     rho_has_changed = TRUE;
  565.     }
  566.  
  567.     rho = parameterArray[0];
  568.  
  569.     if ((rho < 0.0) || (rho > 1.0)) {
  570.     ret_code = KRERR_PARAMETERS;
  571.     return (ret_code);
  572.     }
  573.  
  574.  
  575.     /* Check if network has been modified or learning function has just
  576.        been changed */
  577.  
  578.     if (NetModified || (TopoSortID != ART1_TOPO_TYPE)) {
  579.     (void) kr_topoSort (ART1_TOPO_TYPE);
  580.     ret_code = KernelErrorCode;
  581.     if (ret_code != KRERR_NO_ERROR) {
  582.         NetModified = TRUE;
  583.         return (ret_code);
  584.     } /*if*/
  585.  
  586.     NetModified = FALSE;
  587.     }
  588.  
  589.  
  590.     /* get pointers to resep. first elements of each layer in topo_ptr_array */
  591.  
  592.     topo_ptr = topo_ptr_array+1;
  593.  
  594.     for(i=0; i<=5; i++){
  595.     topo_layer[i] = topo_ptr;
  596.     do {
  597.     } while (*topo_ptr++ != NULL);
  598.  
  599.     }
  600.  
  601.  
  602.     /* Check if input pattern changed since last call to this function */
  603.     if (krart_inp_pat_changed(topo_layer[0])) {
  604.     inp_pat_changed = TRUE;
  605.     krart_save_inp_pat(topo_layer[0]);
  606.     }
  607.  
  608.  
  609.     /* Push activation of input units to their output value.
  610.        This is important for the first cycle. */
  611.  
  612.     topo_ptr = topo_layer[0];
  613.     for (unit_ptr = *topo_ptr; *topo_ptr != NULL; unit_ptr = *topo_ptr++) {
  614.     if (unit_ptr->out_func == OUT_IDENTITY) {
  615.         unit_ptr->Out.output = unit_ptr->act;
  616.     } else {
  617.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  618.     }
  619.  
  620.     } 
  621.  
  622.     /* if rho had changed from last to this call of this update function then
  623.        reinitialize the values of the i_act field of the unit structure and
  624.        reset the activations of all non input units */
  625.     if (rho_has_changed || inp_pat_changed) {
  626.     ret_code = kra1_init_i_act (rho);
  627.     if (ret_code != KRERR_NO_ERROR) 
  628.         return (ret_code);
  629.  
  630.     ret_code = krart_reset_activations ();
  631.     if (ret_code != KRERR_NO_ERROR) 
  632.         return (ret_code);
  633.     }
  634.  
  635.     /* 1 propagation step (all units push their information onto
  636.        their output and calculate their new activation.*/
  637.  
  638.     krart_prop_synch ();
  639.  
  640.     /* look for the recognition unit with the highest activation
  641.        returns a NULL pointer if all recognition units have
  642.        activation 0.0 */
  643.     winner_ptr = krart_get_winner (topo_layer[2],1.0);
  644.  
  645.     return (ret_code);
  646.  
  647. }
  648.  
  649.  
  650.  
  651. /*****************************************************************************
  652.   FUNCTION : UPDATE_ART1_Propagate
  653.  
  654.   PURPOSE  : ART1 Update function for updating until a stable state is reached,
  655.              e.g. either the 'classified' unit is on or the 'not classifiable' 
  656.          unit is.
  657.   RETURNS  : 
  658.   NOTES    :
  659.  
  660.   UPDATE   : 
  661. ******************************************************************************/
  662. krui_err  UPDATE_ART1_Propagate(float *parameterArray, int NoOfParams)
  663. {
  664.     krui_err     ret_code      = KRERR_NO_ERROR;
  665.     int          i;
  666.     struct Unit  *winner_ptr;    /* recogn. unit which is the winner of w.t.a */
  667.     TopoPtrArray topo_layer[6];    /* topo_layer[0] : *first input unit
  668.                    topo_layer[1] : *first comp. unit
  669.                    topo_layer[2] : *first rec.  unit
  670.                    topo_layer[3] : *first delay unit
  671.                    topo_layer[4] : *first local reset unit
  672.                    topo_layer[5] : *first special unit
  673.                    (classified_unit) */
  674.     TopoPtrArray  topo_ptr;
  675.     float         rho;
  676.  
  677.  
  678.     /* Check vigilance parameter */
  679.  
  680.     if (NoOfParams < 1) {
  681.     ret_code = KRERR_PARAMETERS;
  682.     return (ret_code);
  683.     }
  684.  
  685.     rho = parameterArray[0];
  686.  
  687.     if ((rho < 0.0) || (rho > 1.0)) {
  688.     ret_code = KRERR_PARAMETERS;
  689.     return (ret_code);
  690.     }
  691.  
  692.  
  693.     /* Check if network has been modified or learning function has just
  694.        been changed  */
  695.  
  696.     if (NetModified || (TopoSortID != ART1_TOPO_TYPE)) {
  697.     (void) kr_topoSort (ART1_TOPO_TYPE);
  698.     ret_code = KernelErrorCode;
  699.     if (ret_code != KRERR_NO_ERROR) {
  700.         NetModified = TRUE;
  701.         return (ret_code);
  702.     } 
  703.  
  704.     NetModified = FALSE;
  705.     }
  706.  
  707.     ret_code = kra1_init_i_act (rho);
  708.  
  709.     if (ret_code != KRERR_NO_ERROR) {
  710.     return (ret_code);
  711.     }
  712.  
  713.     /* get pointers to resp. first elements of each layer in topo_ptr_array */
  714.  
  715.     topo_ptr = topo_ptr_array+1;
  716.  
  717.     for (i=0; i<=5; i++) {
  718.     topo_layer[i] = topo_ptr;
  719.     do {
  720.     } while (*topo_ptr++ != NULL);
  721.     } 
  722.  
  723.     /* initialize activations of non input units */
  724.  
  725.     ret_code = krart_reset_activations ();
  726.     if (ret_code != KRERR_NO_ERROR) 
  727.     return (ret_code);
  728.  
  729.     do {
  730.     /* 1 propagation step (all units push their information onto
  731.        their output and calculate their new activation */
  732.  
  733.     krart_prop_synch ();
  734.  
  735.     /* look for the recognition unit with the highest activation
  736.        returns a NULL pointer if all recognition units have
  737.        activation 0.0 */
  738.     winner_ptr = krart_get_winner (topo_layer[2],1.0);
  739.  
  740.     } while (!(ART1_CLASSIFIED) && !(ART1_NOT_CLASSIFIABLE));
  741.  
  742.     return (ret_code);
  743.  
  744. }
  745.  
  746.  
  747.  
  748.  
  749. /*****************************************************************************
  750.   FUNCTION : UPDATE_ART2_syncPropagate
  751.  
  752.   PURPOSE  : ART 2 update function which does exactly the same as the normal
  753.              synchronous propagate function except that additionally the winner
  754.          of the ART 1 recognition layer is calculated.
  755.   RETURNS  : 
  756.   NOTES    :
  757.  
  758.   UPDATE   : 
  759. ******************************************************************************/
  760. krui_err  UPDATE_ART2_syncPropagate(float *parameterArray, int NoOfParams)
  761. {
  762.     krui_err     ret_code      = KRERR_NO_ERROR;
  763.     int          i;
  764.     struct Unit  *winner_ptr; /* recogn. unit which is the winner of w.t.a */
  765.     struct Unit  *unit_ptr;
  766.     TopoPtrArray topo_layer[12]; /* topo_layer[0] : *first input unit
  767.                                     topo_layer[1] : *first w unit
  768.                     topo_layer[2] : *first x unit
  769.                     topo_layer[3] : *first u unit
  770.                     topo_layer[4] : *first v unit
  771.                     topo_layer[5] : *first p unit
  772.                     topo_layer[6] : *first q unit
  773.                     topo_layer[7] : *first r unit
  774.                     topo_layer[8] : *first rec.  unit
  775.                     topo_layer[9] : *first local reset unit */
  776.     TopoPtrArray topo_ptr;
  777.     static float rho, param_a, param_b, param_c, param_d, theta;
  778.     bool         inp_pat_changed   = FALSE;
  779.     bool         rho_has_changed   = FALSE;
  780.     bool         a_has_changed     = FALSE;
  781.     bool         b_has_changed     = FALSE;
  782.     bool         c_has_changed     = FALSE;
  783.     bool         theta_has_changed = FALSE;
  784.  
  785.  
  786.  
  787.  
  788.     /* Check vigilance parameter */
  789.  
  790.     if (NoOfParams < 5) {
  791.     ret_code = KRERR_PARAMETERS;
  792.     return (ret_code);
  793.     } 
  794.  
  795.  
  796.     /* Check if input pattern had changed from last step to this one */
  797.  
  798.  
  799.     /* Check if one of the parameters has changed from last to actual
  800.        call of this update function.
  801.        If so, then put new activation value into unit rho or change
  802.        the weights of the relevant links. */
  803.     if (rho != parameterArray[0]) 
  804.     rho_has_changed = TRUE;
  805.  
  806.     if (param_a != parameterArray[1]) 
  807.     a_has_changed = TRUE;
  808.  
  809.     if (param_b != parameterArray[2]) 
  810.     b_has_changed = TRUE;
  811.  
  812.     if (param_c != parameterArray[3]) 
  813.     c_has_changed = TRUE;
  814.  
  815.     if (theta != parameterArray[4]) 
  816.     theta_has_changed = TRUE;
  817.  
  818.     rho     = parameterArray[0];
  819.     param_a = parameterArray[1];
  820.     param_b = parameterArray[2];
  821.     param_c = parameterArray[3];
  822.     theta   = parameterArray[4];
  823.  
  824.  
  825.     /* Check if network has been modified */
  826.  
  827.     if (NetModified || (TopoSortID != ART2_TOPO_TYPE)) {
  828.     (void) kr_topoSort (ART2_TOPO_TYPE);
  829.     ret_code = KernelErrorCode;
  830.     if (ret_code != KRERR_NO_ERROR) {
  831.         NetModified = TRUE;
  832.         return (ret_code);
  833.     } 
  834.     NetModified = FALSE;
  835.     } 
  836.  
  837.     /* get pointers to resp. first elements of each layer in topo_ptr_array */
  838.  
  839.     topo_ptr = topo_ptr_array+1;
  840.  
  841.     for (i=0; i<=9; i++) {
  842.     topo_layer[i] = topo_ptr;
  843.     do {
  844.     } while (*topo_ptr++ != NULL);
  845.     } 
  846.  
  847.     /* Check if input pattern changed since last call to this function */
  848.     if (krart_inp_pat_changed(topo_layer[0])) {
  849.     inp_pat_changed = TRUE;
  850.     krart_save_inp_pat(topo_layer[0]);
  851.     } 
  852.  
  853.  
  854.     /* Read out value of parameter d from bias field of any unit. The
  855.        value has been written into the bias field by the init-function */
  856.     param_d = (*(topo_ptr_array+1))->bias;
  857.  
  858.  
  859.     /* Check values of the parameters */
  860.  
  861.     if ((rho < 0.0) || (rho > 1.0) || (param_a <= 0.0) || (param_b <= 0.0) ||
  862.     ((param_c*param_d)/(1-param_d) > 1.0) ||(theta < 0.0) || (theta > 1.0)){
  863.     ret_code = KRERR_PARAMETERS;
  864.     return (ret_code);
  865.     } 
  866.  
  867.  
  868.     /* if one of the parameters had changed from last to this call
  869.        of this update function then reinitialize the values of the i_act 
  870.        field of the unit structure, set the weights of the relevant links and
  871.        reset the activations of all non input units */
  872.     if (rho_has_changed || a_has_changed || b_has_changed ||
  873.     c_has_changed || theta_has_changed || inp_pat_changed){
  874.  
  875.     ret_code = kra2_set_params (rho,param_a,param_b,param_c,param_d,theta);
  876.  
  877.     if (ret_code != KRERR_NO_ERROR) 
  878.         return (ret_code);
  879.  
  880.     ret_code = kra2_init_propagate();
  881.  
  882.     if (ret_code != KRERR_NO_ERROR) 
  883.         return (ret_code);
  884.  
  885.     kra2_init_pattern();
  886.     }
  887.  
  888.  
  889.     /* Push activation of input units to their output value.
  890.        This is important for the first cycle. */
  891.  
  892.     topo_ptr = topo_layer[ART2_INP_LAY-1];
  893.     unit_ptr = *topo_ptr;
  894.     while (unit_ptr != NULL) {
  895.     if (unit_ptr->out_func == OUT_IDENTITY) {
  896.         unit_ptr->Out.output = unit_ptr->act;
  897.     } else {
  898.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  899.     }
  900.     topo_ptr++;
  901.     unit_ptr = *topo_ptr;
  902.     }
  903.  
  904.     /* compute vector norms */
  905.     kra2_compute_norms();
  906.  
  907.     /* save old activation values of f1-units */
  908.     kra2_save_for_stability_check ();
  909.  
  910.     /* Propagate */
  911.     krart_prop_synch ();
  912.  
  913.     /* Get winner */
  914.     winner_ptr = krart_get_winner (topo_layer[ART2_REC_LAY-1], param_d);
  915.  
  916.     /* Check F1 stability */
  917.     kra2_check_f1_stability ();
  918.  
  919.     /* Check reset */
  920.     kra2_checkReset ();
  921.  
  922.     return (ret_code);
  923.  
  924. }
  925.  
  926.  
  927.  
  928. /*****************************************************************************
  929.   FUNCTION : UPDATE_ART2_Propagate 
  930.  
  931.   PURPOSE  :
  932.   RETURNS  : 
  933.   NOTES    :
  934.  
  935.   UPDATE   : 
  936. ******************************************************************************/
  937. krui_err  UPDATE_ART2_Propagate(float *parameterArray, int NoOfParams)
  938. {
  939.     krui_err     ret_code      = KRERR_NO_ERROR;
  940.     int          i;
  941.     struct Unit  *winner_ptr; /* recogn. unit which is the winner of w.t.a */
  942.     TopoPtrArray topo_layer[12]; /* topo_layer[0] : *first input unit
  943.                                           topo_layer[1] : *first w unit
  944.                                           topo_layer[2] : *first x unit
  945.                                           topo_layer[3] : *first u unit
  946.                                           topo_layer[4] : *first v unit
  947.                                           topo_layer[5] : *first p unit
  948.                                           topo_layer[6] : *first q unit
  949.                                           topo_layer[7] : *first r unit
  950.                                           topo_layer[8] : *first rec. unit
  951.                                           topo_layer[10] : *first local reset
  952.                                        unit */
  953.     TopoPtrArray topo_ptr;
  954.     FlintType    rho, param_a, param_b, param_c, param_d, theta;
  955.  
  956.  
  957.     /* Check number of incoming parameters */
  958.  
  959.     if (NoOfParams < 5) {
  960.     ret_code = KRERR_PARAMETERS;
  961.     return (ret_code);
  962.     } 
  963.  
  964.     rho     = parameterArray[0];
  965.     param_a = parameterArray[1];
  966.     param_b = parameterArray[2];
  967.     param_c = parameterArray[3];
  968.     theta   = parameterArray[4];
  969.  
  970.  
  971.  
  972.     /* Check if network has been modified or learning function has just
  973.        been changed */
  974.  
  975.     if (NetModified || (TopoSortID != ART2_TOPO_TYPE)) {
  976.     (void) kr_topoSort (ART2_TOPO_TYPE);
  977.     ret_code = KernelErrorCode;
  978.     if (ret_code != KRERR_NO_ERROR) {
  979.         NetModified = TRUE;
  980.         return (ret_code);
  981.     } 
  982.  
  983.     NetModified = FALSE;
  984.     } 
  985.  
  986.  
  987.     /* Read out value of parameter d from bias field of any unit. The
  988.        value has been written into the bias field by the init-function */
  989.     param_d = (*(topo_ptr_array+1))->bias;
  990.  
  991.  
  992.     /* Check values of the parameters */
  993.  
  994.     if ((rho < 0.0) || (rho > 1.0) ||(param_a <= 0.0) || (param_b <= 0.0) ||
  995.     ((param_c*param_d)/(1-param_d)>1.0) || (theta<0.0) || (theta>1.0)){
  996.     ret_code = KRERR_PARAMETERS;
  997.     return (ret_code);
  998.     }
  999.  
  1000.     ret_code = kra2_set_params (rho, param_a, param_b, param_c, param_d, theta);
  1001.  
  1002.     if (ret_code != KRERR_NO_ERROR) 
  1003.     return (ret_code);
  1004.  
  1005.     ret_code = kra2_init_propagate ();
  1006.  
  1007.     if (ret_code != KRERR_NO_ERROR) 
  1008.     return (ret_code);
  1009.  
  1010.     /* get pointers to resp. first elements of each layer in topo_ptr_array */
  1011.     topo_ptr = topo_ptr_array+1;
  1012.  
  1013.     for (i=0; i<=9; i++){
  1014.     topo_layer[i] = topo_ptr;
  1015.     do {
  1016.     } while (*topo_ptr++ != NULL);
  1017.     }
  1018.  
  1019.  
  1020.     /* initialize the unit activations of the whole net */
  1021.     ret_code = krart_reset_activations();
  1022.     if (ret_code != KRERR_NO_ERROR)
  1023.     return (ret_code);
  1024.  
  1025.     /* initialize of ART2 Simulator for new pattern */
  1026.     kra2_init_pattern ();
  1027.  
  1028.  
  1029.     /* repeat synchronous propagation and look for winner until pattern is
  1030.        classified or network tells us, that pattern is not classifiable */
  1031.     do {
  1032.     /* compute vector norms */
  1033.     kra2_compute_norms();
  1034.  
  1035.     /* save old activation values of f1-units */
  1036.     kra2_save_for_stability_check ();
  1037.  
  1038.     /* 1 propagation step (all units push their information onto
  1039.        their output and calculate their new activation.  */
  1040.     krart_prop_synch ();
  1041.  
  1042.     /* look for the recognition unit with the highest activation returns
  1043.        a NULL pointer if all recognition units have activation 0.0 */
  1044.     winner_ptr = krart_get_winner (topo_layer[ART2_REC_LAY-1], param_d);
  1045.  
  1046.     /* Check if F1-Layer is stable */
  1047.     kra2_check_f1_stability();
  1048.  
  1049.     /* Check Reset */
  1050.     kra2_checkReset ();
  1051.  
  1052.     } while (!(ART2_CLASSIFIED) && !(ART2_NOT_CLASSIFIABLE));
  1053.  
  1054.     return (ret_code);
  1055. }
  1056.  
  1057.  
  1058. /*****************************************************************************
  1059.   FUNCTION : UPDATE_ARTMAP_syncPropagate
  1060.  
  1061.   PURPOSE  : ARTMAP update function which does exactly the same as the normal
  1062.              synchronous propagate function except that additionally the winner
  1063.          of the ARTMAP recognition layer is calculated.
  1064.   RETURNS  : 
  1065.   NOTES    :
  1066.  
  1067.   UPDATE   : 
  1068. ******************************************************************************/
  1069. krui_err  UPDATE_ARTMAP_syncPropagate(float *parameterArray, int NoOfParams)
  1070. {
  1071.     krui_err     ret_code      = KRERR_NO_ERROR;
  1072.     int          i;
  1073.     struct Unit  *winner_ptr_a;    /* the winner of wta of ARTa */
  1074.     struct Unit  *winner_ptr_b;    /* the winner of w.t.a of ARTb */
  1075.     struct Unit  *unit_ptr;
  1076.     TopoPtrArray topo_layer[14]; /* topo_layer[0] : *first input unit ARTa
  1077.                                     topo_layer[1] : *first comp. unit ARTa
  1078.                     topo_layer[2] : *first rec.  unit ARTa
  1079.                     topo_layer[3] : *first delay unit ARTa
  1080.                     topo_layer[4] : *first local reset unit ARTa
  1081.                     topo_layer[5] : *first special unit ARTa
  1082.                     (classified_unit)
  1083.                     topo_layer[6] : *first input unit ARTb
  1084.                     topo_layer[7] : *first comp. unit ARTb
  1085.                     topo_layer[8] : *first rec.  unit ARTb
  1086.                     topo_layer[9] : *first delay unit ARTb
  1087.                     topo_layer[10]: *first local reset unit ARTb
  1088.                     topo_layer[11]: *first special unit ARTb
  1089.                     (classified_unit)
  1090.                                     topo_layer[12]: *first map unit
  1091.                     topo_layer[13]: *first special map unit */
  1092.     TopoPtrArray topo_ptr;
  1093.     static float rho_a = -1.0;
  1094.     static float rho_b = -1.0;
  1095.     static float rho   = -1.0;
  1096.     bool         inp_pat_changed   = FALSE;
  1097.     bool         rho_has_changed   = FALSE;
  1098.  
  1099.  
  1100.     /* Check vigilance parameter */
  1101.     if (NoOfParams < 3) {
  1102.     ret_code = KRERR_PARAMETERS;
  1103.     return (ret_code);
  1104.     } 
  1105.  
  1106.     /* Check if rho has changed from last to actual call of this update function
  1107.        If rho has changed, then put new activation value into unit rho */
  1108.     if ((rho_a != parameterArray[0]) || (rho_b != parameterArray[1]) ||
  1109.     (rho   != parameterArray[2]))
  1110.     rho_has_changed = TRUE;
  1111.  
  1112.     rho_a = parameterArray[0];
  1113.     rho_b = parameterArray[1];
  1114.     rho   = parameterArray[2];
  1115.  
  1116.  
  1117.     if((rho_a<0.0) || (rho_a>1.0) || (rho_b<0.0) || (rho_b>1.0) ||
  1118.        (rho<0.0) || (rho>1.0)){
  1119.     ret_code = KRERR_PARAMETERS;
  1120.     return (ret_code);
  1121.     }
  1122.  
  1123.  
  1124.     /* Check if network has been modified or learn func has just been changed */
  1125.  
  1126.     if (NetModified || (TopoSortID != ARTMAP_TOPO_TYPE)) {
  1127.     (void) kr_topoSort (ARTMAP_TOPO_TYPE);
  1128.     ret_code = KernelErrorCode;
  1129.     if (ret_code != KRERR_NO_ERROR) {
  1130.         NetModified = TRUE;
  1131.         return (ret_code);
  1132.     } 
  1133.  
  1134.     NetModified = FALSE;
  1135.     }
  1136.  
  1137.  
  1138.     /* get pointers to resp. first elements of each layer in topo_ptr_array */
  1139.     topo_ptr = topo_ptr_array+1;
  1140.  
  1141.     for (i=0; i<=13; i++) {
  1142.     topo_layer[i] = topo_ptr;
  1143.     do {
  1144.     } while (*topo_ptr++ != NULL);
  1145.     }
  1146.  
  1147.  
  1148.     /* Check if input pattern changed since last call to this function */
  1149.     if (krart_inp_pat_changed(topo_layer[0]) ||
  1150.     krart_inp_pat_changed(topo_layer[6])){
  1151.     inp_pat_changed = TRUE;
  1152.     krart_save_inp_pat(topo_layer[0]);
  1153.     krart_save_inp_pat(topo_layer[6]);
  1154.     } 
  1155.  
  1156.  
  1157.     /* Push activation of input units to their output value.
  1158.        This is important for the first cycle. */
  1159.  
  1160.     /* inpa - units */
  1161.     topo_ptr = topo_layer[0];
  1162.     for (unit_ptr = *topo_ptr; *topo_ptr != NULL; unit_ptr = *++topo_ptr) {
  1163.     if (unit_ptr->out_func == OUT_IDENTITY) {
  1164.         unit_ptr->Out.output = unit_ptr->act;
  1165.     } else {
  1166.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  1167.     } 
  1168.     } 
  1169.  
  1170.     topo_ptr = topo_layer[6];
  1171.     for (unit_ptr = *topo_ptr; *topo_ptr != NULL; unit_ptr = *++topo_ptr) {
  1172.     if (unit_ptr->out_func == OUT_IDENTITY) {
  1173.         unit_ptr->Out.output = unit_ptr->act;
  1174.     } else {
  1175.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  1176.     }
  1177.     }
  1178.  
  1179.     /* if rho or input pattern had changed from last to this call of this
  1180.        update function then reinitialize the values of the i_act field of the 
  1181.        unit structure and reset the activations of all non input units */
  1182.     if (rho_has_changed || inp_pat_changed) {
  1183.  
  1184.     ret_code = kram_init_i_act (rho_a, rho_b, rho);
  1185.     if (ret_code != KRERR_NO_ERROR)
  1186.         return (ret_code);
  1187.  
  1188.     ret_code = krart_reset_activations ();
  1189.     if (ret_code != KRERR_NO_ERROR) 
  1190.         return (ret_code);
  1191.     } 
  1192.  
  1193.     /* 1 propagation step (all units push their information onto
  1194.        their output and calculate their new activation. */
  1195.  
  1196.     krart_prop_synch ();
  1197.  
  1198.     /* look for the recognition unit with the highest activation returns a 
  1199.        NULL pointer if all recognition units have activation 0.0 */
  1200.     winner_ptr_a = krart_get_winner (topo_layer[2],1.0);
  1201.     winner_ptr_b = krart_get_winner (topo_layer[8],1.0);
  1202.  
  1203.     return (ret_code);
  1204.  
  1205. }
  1206.  
  1207.  
  1208. /*****************************************************************************
  1209.   FUNCTION : UPDATE_ARTMAP_Propagate
  1210.  
  1211.   PURPOSE  : ARTMAP Update function for updating until a stable state is 
  1212.              reached, e.g. either the 'classified' unit is on or the 'not 
  1213.          classifiable' unit is.
  1214.   RETURNS  : 
  1215.   NOTES    :
  1216.  
  1217.   UPDATE   : 
  1218. ******************************************************************************/
  1219. krui_err  UPDATE_ARTMAP_Propagate(float *parameterArray, int NoOfParams)
  1220. {
  1221.     krui_err     ret_code      = KRERR_NO_ERROR;
  1222.     int          i;
  1223.     struct Unit  *winner_ptr_a;    /* the winner of w.t.a of ARTa */
  1224.     struct Unit  *winner_ptr_b;    /* the winner of w.t.a of ARTb */
  1225.     TopoPtrArray topo_layer[14]; /* topo_layer[0] : *first input unit ARTa
  1226.                                     topo_layer[1] : *first comp. unit ARTa
  1227.                     topo_layer[2] : *first rec.  unit ARTa
  1228.                     topo_layer[3] : *first delay unit ARTa
  1229.                     topo_layer[4] : *first local reset unit ARTa
  1230.                     topo_layer[5] : *first special unit ARTa
  1231.                     (classified_unit)
  1232.                                     topo_layer[6] : *first input unit ARTb
  1233.                     topo_layer[7] : *first comp. unit ARTb
  1234.                     topo_layer[8] : *first rec.  unit ARTb
  1235.                     topo_layer[9] : *first delay unit ARTb
  1236.                     topo_layer[10]: *first local reset unit ARTb
  1237.                     topo_layer[11]: *first special unit ARTb
  1238.                     (classified_unit)
  1239.                                     topo_layer[12]: *first map unit
  1240.                     topo_layer[13]: *first special map unit */
  1241.     TopoPtrArray topo_ptr;
  1242.     float        rho_a;
  1243.     float        rho_b;
  1244.     float        rho;
  1245.  
  1246.  
  1247.     /* Check vigilance parameters */
  1248.  
  1249.     if (NoOfParams < 3) {
  1250.     ret_code = KRERR_PARAMETERS;
  1251.     return (ret_code);
  1252.     } 
  1253.  
  1254.     rho_a = parameterArray[0];
  1255.     rho_b = parameterArray[1];
  1256.     rho   = parameterArray[2];
  1257.  
  1258.     if ((rho_a < 0.0) || (rho_a > 1.0) || (rho_b < 0.0) ||
  1259.     (rho_b > 1.0) || (rho   < 0.0) || (rho   > 1.0)){
  1260.     ret_code = KRERR_PARAMETERS;
  1261.     return (ret_code);
  1262.     } 
  1263.  
  1264.  
  1265.     /* Check if network has been modified or learn func has just been changed */
  1266.     if (NetModified || (TopoSortID != ARTMAP_TOPO_TYPE)) {
  1267.     (void) kr_topoSort (ARTMAP_TOPO_TYPE);
  1268.     ret_code = KernelErrorCode;
  1269.     if (ret_code != KRERR_NO_ERROR) {
  1270.         NetModified = TRUE;
  1271.         return (ret_code);
  1272.     } 
  1273.  
  1274.     NetModified = FALSE;
  1275.     }
  1276.  
  1277.  
  1278.     ret_code = kram_init_i_act (rho_a, rho_b, rho);
  1279.  
  1280.     if (ret_code != KRERR_NO_ERROR) 
  1281.     return (ret_code);
  1282.  
  1283.     /* get pointers to resp. first elements of each layer in topo_ptr_array */
  1284.     topo_ptr = topo_ptr_array+1;
  1285.  
  1286.     for (i=0; i<=13; i++) {
  1287.     topo_layer[i] = topo_ptr;
  1288.     do {
  1289.     } while (*topo_ptr++ != NULL);
  1290.     } 
  1291.  
  1292.     /* initialize activations of non input units */
  1293.     ret_code = krart_reset_activations ();
  1294.     if (ret_code != KRERR_NO_ERROR) 
  1295.     return (ret_code);
  1296.  
  1297.     do {
  1298.     /* 1 propagation step (all units push their information onto
  1299.        their output and calculate their new activation. */
  1300.     krart_prop_synch ();
  1301.  
  1302.     /* look for the recognition unit with the highest activation
  1303.        returns a NULL pointer if all recognition units have
  1304.        activation 0.0 */
  1305.     winner_ptr_a = krart_get_winner (topo_layer[2],1.0);
  1306.     winner_ptr_b = krart_get_winner (topo_layer[8],1.0);
  1307.  
  1308.     } while (!(ARTMAP_CLASSIFIED) && !(ARTMAP_NOT_CLASSIFIABLE));
  1309.  
  1310.     return (ret_code);
  1311.  
  1312. }
  1313.  
  1314.  
  1315.  
  1316. /*****************************************************************************
  1317.   FUNCTION : UPDATE_CC_Propagate
  1318.  
  1319.   PURPOSE  : Propagates a pattern through the net after pressing the test 
  1320.              button.
  1321.   NOTES    :
  1322.  
  1323.   UPDATE   : 5.2.93
  1324. ******************************************************************************/
  1325. krui_err UPDATE_CC_Propagate(float parameterArray[],  int NoOfParams)
  1326. {
  1327.     register struct Unit  *inputUnitPtr,*outputUnitPtr,*hiddenUnitPtr,*unitPtr;
  1328.     register int dummy,o;
  1329.   
  1330.     if(NetModified || LearnFuncHasChanged) {
  1331.     
  1332.     NoOfInputUnits = NoOfHiddenUnits = NoOfOutputUnits = 0;
  1333.     FOR_ALL_UNITS(unitPtr) {
  1334.         if(IS_INPUT_UNIT(unitPtr) && UNIT_IN_USE(unitPtr)) {
  1335.         NoOfInputUnits++;
  1336.         }
  1337.         if(IS_HIDDEN_UNIT(unitPtr) && UNIT_IN_USE(unitPtr)) {
  1338.         NoOfHiddenUnits++;
  1339.         }
  1340.         if(IS_OUTPUT_UNIT(unitPtr) && UNIT_IN_USE(unitPtr)) {
  1341.         NoOfOutputUnits++;
  1342.         }
  1343.     }
  1344.     cc_update = 1;
  1345.     KernelErrorCode = cc_deleteAllSpecialUnits();
  1346.     ERROR_CHECK; 
  1347.  
  1348.     KernelErrorCode = kr_topoSort(TOPOLOGICAL_CC);
  1349.     ERROR_CHECK; 
  1350.  
  1351.     KernelErrorCode = cc_setPointers();
  1352.     ERROR_CHECK;
  1353.  
  1354.     NetModified = FALSE;
  1355.     LearnFuncHasChanged = FALSE;
  1356.     }
  1357.  
  1358.     FOR_ALL_INPUT_UNITS(inputUnitPtr,dummy){
  1359.     if(inputUnitPtr->out_func == OUT_IDENTITY) {
  1360.         inputUnitPtr->Out.output = inputUnitPtr->act;
  1361.     }else{
  1362.         inputUnitPtr->Out.output = 
  1363.         (*inputUnitPtr->out_func) (inputUnitPtr->act);
  1364.     }
  1365.     }
  1366.  
  1367.     FOR_ALL_HIDDEN_UNITS(hiddenUnitPtr,dummy) {
  1368.     hiddenUnitPtr->act = (*hiddenUnitPtr->act_func) (hiddenUnitPtr);
  1369.     if(hiddenUnitPtr->out_func == OUT_IDENTITY) {
  1370.         hiddenUnitPtr->Out.output = hiddenUnitPtr->act;
  1371.     }else{
  1372.         hiddenUnitPtr->Out.output = 
  1373.         (*hiddenUnitPtr->out_func) (hiddenUnitPtr->act);
  1374.     }
  1375.     }
  1376.     
  1377.     FOR_ALL_OUTPUT_UNITS(outputUnitPtr,o) {
  1378.     outputUnitPtr->act = (*outputUnitPtr->act_func) (outputUnitPtr);
  1379.     if(outputUnitPtr->out_func == OUT_IDENTITY) {
  1380.         outputUnitPtr->Out.output = outputUnitPtr->act;
  1381.     }else{
  1382.         outputUnitPtr->Out.output = 
  1383.         (*outputUnitPtr->out_func) (outputUnitPtr->act);
  1384.     }
  1385.     }
  1386.     return(KRERR_NO_ERROR);
  1387. }
  1388.  
  1389.  
  1390.  
  1391. /*****************************************************************************
  1392.   FUNCTION : UPDATE_RCC_Propagate
  1393.  
  1394.   PURPOSE  : Propagates a pattern through the net after pressing the test 
  1395.              button.
  1396.   NOTES    :
  1397.  
  1398.   UPDATE   : 5.2.93
  1399. ******************************************************************************/
  1400. krui_err UPDATE_RCC_Propagate(float parameterArray[], int NoOfParams)
  1401. {
  1402.     register struct Unit  *inputUnitPtr,*outputUnitPtr,*hiddenUnitPtr,*unitPtr;
  1403.     register int dummy,o;
  1404.     static int oldNoOfPatterns=0;
  1405.  
  1406.   
  1407.  
  1408.     if(NetModified || (krui_getNoOfPatterns() != oldNoOfPatterns) || 
  1409.        LearnFuncHasChanged) {
  1410.  
  1411.     KernelErrorCode = rcc_searchRecurrentLinks();
  1412.     ERROR_CHECK;
  1413.  
  1414.     rcc_manageResetArray(0,kr_TotalNoOfPattern()-1,1);
  1415.     oldNoOfPatterns = krui_getNoOfPatterns();
  1416.     NoOfInputUnits = NoOfHiddenUnits = NoOfOutputUnits = 0;
  1417.  
  1418.     FOR_ALL_UNITS(unitPtr) {
  1419.         if(IS_INPUT_UNIT(unitPtr) && UNIT_IN_USE(unitPtr)) {
  1420.         NoOfInputUnits++;
  1421.         }
  1422.         if(IS_HIDDEN_UNIT(unitPtr) && UNIT_IN_USE(unitPtr)) {
  1423.         NoOfHiddenUnits++;
  1424.         }
  1425.         if(IS_OUTPUT_UNIT(unitPtr) && UNIT_IN_USE(unitPtr)) {
  1426.         NoOfOutputUnits++;
  1427.         }
  1428.     }
  1429.     cc_update = 1;
  1430.     KernelErrorCode = cc_deleteAllSpecialUnits();
  1431.     ERROR_CHECK; 
  1432.  
  1433.     KernelErrorCode = kr_topoSort(TOPOLOGICAL_RCC);
  1434.     ERROR_CHECK; 
  1435.  
  1436.     KernelErrorCode = cc_setPointers();
  1437.     ERROR_CHECK;
  1438.  
  1439.     LearnFuncHasChanged = FALSE;
  1440.     NetModified = FALSE;
  1441.     }
  1442.   
  1443.     if (((int)reset[rcc_currentPattern]) == 1) {
  1444.     printf("New pattern starts \n");
  1445.     }
  1446.  
  1447.     FOR_ALL_INPUT_UNITS(inputUnitPtr,dummy){
  1448.     if(inputUnitPtr->out_func == OUT_IDENTITY) {
  1449.         inputUnitPtr->Out.output = inputUnitPtr->act;
  1450.     }else{
  1451.         inputUnitPtr->Out.output = 
  1452.         (*inputUnitPtr->out_func) (inputUnitPtr->act);
  1453.     }
  1454.     }
  1455.  
  1456.     FOR_ALL_HIDDEN_UNITS(hiddenUnitPtr,dummy) {
  1457.     hiddenUnitPtr->lln = reset[rcc_currentPattern];
  1458.     hiddenUnitPtr->act = (*hiddenUnitPtr->act_func) (hiddenUnitPtr);
  1459.     if(hiddenUnitPtr->out_func == OUT_IDENTITY) {
  1460.         hiddenUnitPtr->Out.output = hiddenUnitPtr->act;
  1461.     }else{
  1462.         hiddenUnitPtr->Out.output = 
  1463.         (*hiddenUnitPtr->out_func) (hiddenUnitPtr->act);
  1464.     }
  1465.     }
  1466.     
  1467.     FOR_ALL_OUTPUT_UNITS(outputUnitPtr,o) {
  1468.     outputUnitPtr->lln = reset[rcc_currentPattern];
  1469.     outputUnitPtr->act = (*outputUnitPtr->act_func) (outputUnitPtr);
  1470.     if(outputUnitPtr->out_func == OUT_IDENTITY) {
  1471.         outputUnitPtr->Out.output = outputUnitPtr->act;
  1472.     }else{
  1473.         outputUnitPtr->Out.output = 
  1474.         (*outputUnitPtr->out_func) (outputUnitPtr->act);
  1475.     }
  1476.     }
  1477.     return(KRERR_NO_ERROR);
  1478. }
  1479.  
  1480.  
  1481.  
  1482. /*****************************************************************************
  1483.   FUNCTION : UPDATE_DLVQ_Propagate
  1484.  
  1485.   PURPOSE  :
  1486.   RETURNS  : 
  1487.   NOTES    :
  1488.  
  1489.   UPDATE   : 
  1490. ******************************************************************************/
  1491. krui_err UPDATE_DLVQ_Propagate(float parameterArray[], int NoOfParams)
  1492. {
  1493.     struct Unit *inputUnitPtr,*hiddenUnitPtr,*maxActivatedUnitPtr=NULL;
  1494.     double maxAct,act;
  1495.     int i,h,startPattern,endPattern,d1,d2,d3,generatedNewUnit,noOfLinks;
  1496.  
  1497.     if(newPatternsLoaded){
  1498.     newPatternsLoaded = 0;
  1499.     startPattern = 0;
  1500. /*    endPattern = krui_getNoOfPatterns()-1;*/
  1501.     endPattern = kr_TotalNoOfSubPatPairs()-1;
  1502.     KernelErrorCode = getNoOfClasses(startPattern,endPattern);
  1503.     ERROR_CHECK;
  1504.  
  1505.     normPatterns(startPattern,endPattern);
  1506.     allocInitialUnitArray();
  1507.     initInitialUnitArray(startPattern,endPattern);
  1508.     }
  1509.  
  1510.     if(NetModified || LearnFuncHasChanged) {
  1511.     NoOfInputUnits = NoOfHiddenUnits = NoOfOutputUnits = 0;
  1512.     FOR_ALL_UNITS(unitPtr) {
  1513.         if(IS_INPUT_UNIT(unitPtr) && UNIT_IN_USE(unitPtr)) {
  1514.         NoOfInputUnits++;
  1515.         }
  1516.         if(IS_HIDDEN_UNIT(unitPtr) && UNIT_IN_USE(unitPtr)) {
  1517.         NoOfHiddenUnits++;
  1518.         }
  1519.         if(IS_OUTPUT_UNIT(unitPtr) && UNIT_IN_USE(unitPtr)) {
  1520.         NoOfOutputUnits++;
  1521.         }
  1522.     }
  1523.     if(NoOfOutputUnits != 1){
  1524.         return(DLVQ_ERROR3); /* Wrong no. of output units */
  1525.     }
  1526.     allocArrays();
  1527.     KernelErrorCode = kr_topoSort(TOPOLOGICAL_FF);
  1528.     ERROR_CHECK;    
  1529.  
  1530.     KernelErrorCode = dlvq_setPointers();
  1531.     ERROR_CHECK; 
  1532.  
  1533.     krui_getNetInfo(&d1,&noOfLinks,&d2,&d3);
  1534.     if(noOfLinks != NoOfInputUnits * NoOfHiddenUnits + NoOfHiddenUnits) {
  1535.         return(DLVQ_ERROR4); /* wrong topology */
  1536.     }
  1537.  
  1538.     generateMissingClassHiddenUnits(&generatedNewUnit);
  1539.     if(generatedNewUnit) {
  1540.         return(DLVQ_ERROR5); /* There is not a class for every unit */
  1541.     }
  1542.     NetModified = FALSE;
  1543.     LearnFuncHasChanged = FALSE;
  1544.     }
  1545.  
  1546.     FOR_ALL_INPUT_UNITS(inputUnitPtr,i){
  1547.     inputUnitPtr->Out.output = inputUnitPtr->act;
  1548.     }
  1549.   
  1550.     maxAct = -1.0;
  1551.  
  1552.     FOR_ALL_HIDDEN_UNITS(hiddenUnitPtr,h) {
  1553.     hiddenUnitPtr->Out.output = hiddenUnitPtr->act = act = 0.0;
  1554.     FOR_ALL_LINKS(hiddenUnitPtr,linkPtr) {
  1555.         act += linkPtr->weight * linkPtr->to->Out.output;
  1556.     }
  1557.     if(maxAct < act){
  1558.         maxAct = act;
  1559.         maxActivatedUnitPtr = hiddenUnitPtr;
  1560.     }
  1561.     }
  1562.  
  1563.     maxActivatedUnitPtr->Out.output = maxActivatedUnitPtr->act = 1.0;
  1564.     (*FirstOutputUnitPtr)->Out.output = 
  1565.     (*FirstOutputUnitPtr)->act = maxActivatedUnitPtr->bias;
  1566.     return(KRERR_NO_ERROR);
  1567.  
  1568.  
  1569.  
  1570. /*****************************************************************************
  1571.   FUNCTION : UPDATE_BPTT
  1572.  
  1573.   PURPOSE  : Backpropagation through time synchronous order using activity 
  1574.              buffer for each unit.
  1575.   RETURNS  : 
  1576.   NOTES    : The "TEST" button in the remote panel first increases the pattern 
  1577.              number, copies the input pattern to the input units and, 
  1578.          depending on the setting of the "SHOW" button,
  1579.             - does not copy the output pattern with setting "none"
  1580.         - copies the output pattern to unit_ptr->act with setting 
  1581.           "activation"
  1582.         - copies the output pattern to unit_ptr->act and 
  1583.           unit_ptr->Out.output with setting "output"
  1584.          An all-zero-input pattern for reset is only effective using 
  1585.          "TEST" if the current pattern is the pattern immediatly before 
  1586.          the reset pattern.
  1587.   UPDATE   : 
  1588. ******************************************************************************/
  1589. krui_err  UPDATE_BPTT(float *parameterArray, int NoOfParams)
  1590. {
  1591.     krui_err ret_code;
  1592.     register struct Unit   *unit_ptr;
  1593.     register TopoPtrArray  topo_ptr;
  1594.     register TopoPtrArray  first_hidden_ptr;
  1595.     int all_zero_input=1;    /* flag to reset net-copies */
  1596.     int done_hidden;
  1597.  
  1598.     if (NetModified || (TopoSortID != TOPOLOGIC_TYPE)){
  1599.     /* Net has been modified or topologic array isn't initialized */
  1600.     /* any connected topology allowed */
  1601.     /* count the no. of I/O units and check the patterns  */
  1602.     ret_code = kr_IOCheck();
  1603.     if (ret_code < KRERR_NO_ERROR)  
  1604.         return( ret_code );
  1605.       
  1606.     /* sort units by ''topologic type'',
  1607.        criterion is visibility (input,hidden,output), not topology */
  1608.     ret_code = kr_topoSort( TOPOLOGIC_TYPE );
  1609.     if ((ret_code != KRERR_NO_ERROR) && (ret_code != KRERR_DEAD_UNITS))
  1610.         return( ret_code );
  1611.       
  1612.     NetModified = FALSE;
  1613.     }
  1614.   
  1615.  
  1616.     /* check all zero pattern in input layer => reset net_activities */
  1617.     topo_ptr = topo_ptr_array;
  1618.  
  1619.     while ((unit_ptr = *++topo_ptr) != NULL) {
  1620.     unit_ptr->Out.output = unit_ptr->act;
  1621.     if(fabs(unit_ptr->act)>0.0001) all_zero_input = 0; /* no reset-input */
  1622.     }
  1623.     first_hidden_ptr = topo_ptr;
  1624.  
  1625.     if (all_zero_input) {    /* clear netact-copies */
  1626.     FOR_ALL_UNITS( unit_ptr ) unit_ptr->i_act = 0.0;
  1627.     }
  1628.  
  1629.     /* copy last unit_ptr->i_act to unit_ptr->Out.output */
  1630.     /*  one step back in time, make most recent activity
  1631.     visible in unit_ptr->Out.output for subsequent calls to act_func */
  1632.  
  1633.     while ((unit_ptr = *++topo_ptr) != NULL) { /* hidden layer */
  1634.     unit_ptr->Out.output = unit_ptr->i_act; }
  1635.  
  1636.     while ((unit_ptr = *++topo_ptr) != NULL) { /* output layer */
  1637.     unit_ptr->Out.output = unit_ptr->i_act; }
  1638.  
  1639.     /*  calculate new activities for hidden and output units */
  1640.     /* point to first hidden unit */
  1641.     topo_ptr = first_hidden_ptr;
  1642.     done_hidden=0;
  1643.     while ( ((unit_ptr = *++topo_ptr) != NULL) || (done_hidden==0))
  1644.     if (unit_ptr == NULL) {
  1645.         done_hidden = 1;
  1646.     }else{  
  1647.         /* calc act using i_act copied to Out.output,  SYNCHRONOUS UPDATE:
  1648.            don't update Out.output while updating units, wait until all 
  1649.            units are processed  */
  1650.         unit_ptr->act = (*unit_ptr->act_func) (unit_ptr);
  1651.     }
  1652.  
  1653.     /*  calculate new Out.output values from act by calling out_func,
  1654.     and save values in i_act (since they may be disturbed by show pattern)*/
  1655.  
  1656.     /* point to first hidden unit */
  1657.     topo_ptr = first_hidden_ptr;
  1658.     done_hidden=0;
  1659.     while ( ((unit_ptr = *++topo_ptr) != NULL) || (done_hidden==0))
  1660.     if (unit_ptr == NULL) {
  1661.         done_hidden = 1;
  1662.     }else{  
  1663.         if (unit_ptr->out_func == OUT_IDENTITY) {
  1664.         unit_ptr->Out.output = unit_ptr->act;
  1665.         }else{
  1666.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  1667.         }
  1668.         unit_ptr->i_act = unit_ptr->Out.output;
  1669.     }
  1670.  
  1671.     return( KRERR_NO_ERROR );
  1672.  
  1673.  
  1674.  
  1675. /*****************************************************************************
  1676.   FUNCTION : UPDATE_BAM
  1677.  
  1678.   PURPOSE  :
  1679.   RETURNS  : 
  1680.   NOTES    :
  1681.  
  1682.   UPDATE   : 
  1683. ******************************************************************************/
  1684. krui_err  UPDATE_BAM(float *parameterArray, int NoOfParams)
  1685. {
  1686.     krui_err ret_code;
  1687.     register struct Unit   *unit_ptr;
  1688.     register TopoPtrArray  topo_ptr;
  1689.     register TopoPtrArray  first_hidden_ptr;
  1690.     int all_zero_input=1;    /* flag to reset net-copies */
  1691.     int done_hidden;
  1692.     FlintType new_output;
  1693.  
  1694.     if (NetModified || (TopoSortID != TOPOLOGIC_TYPE)){
  1695.     /* Net has been modified or topologic array isn't initialized */
  1696.     /* any connected topology allowed */
  1697.     /* count the no. of I/O units and check the patterns  */
  1698.     ret_code = kr_IOCheck();
  1699.     if (ret_code < KRERR_NO_ERROR)  
  1700.         return( ret_code );
  1701.       
  1702.     /* sort units by ''topologic type'',
  1703.        criterion is visibility (input,hidden,output), not topology */
  1704.     ret_code = kr_topoSort( TOPOLOGIC_TYPE );
  1705.     if ((ret_code != KRERR_NO_ERROR) && (ret_code != KRERR_DEAD_UNITS))
  1706.         return( ret_code );
  1707.       
  1708.     NetModified = FALSE;
  1709.     }
  1710.  
  1711.     /* Search hidden Units */  
  1712.     topo_ptr = topo_ptr_array;
  1713.     while ((unit_ptr = *++topo_ptr) != NULL) {
  1714.     }
  1715.     first_hidden_ptr = topo_ptr;
  1716.  
  1717.     /*  calculate new Out.output values from act by calling out_func */
  1718.     /* point to first hidden unit and remember the old ones*/
  1719.     topo_ptr = first_hidden_ptr;
  1720.     done_hidden=0;
  1721.     while ( ((unit_ptr = *++topo_ptr) != NULL) || (done_hidden==0))
  1722.     if (unit_ptr == NULL) {
  1723.         done_hidden = 1;
  1724.     }else{  
  1725.         unit_ptr->value_a = unit_ptr->Out.output;
  1726.         if (unit_ptr->out_func == OUT_IDENTITY) {
  1727.         unit_ptr->Out.output = unit_ptr->act;
  1728.         }else{
  1729.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  1730.         }
  1731.     }
  1732.  
  1733.  
  1734.     /*  calculate new activities for hidden and output units */
  1735.     /* point to first hidden unit */
  1736.     topo_ptr = first_hidden_ptr;
  1737.     done_hidden=0;
  1738.     while ( ((unit_ptr = *++topo_ptr) != NULL) || (done_hidden==0))
  1739.     if (unit_ptr == NULL) {
  1740.         done_hidden = 1;
  1741.     }else{ 
  1742.         /* save new value and restore old value from output */
  1743.         new_output = unit_ptr->Out.output; 
  1744.         unit_ptr->Out.output = unit_ptr->value_a; 
  1745.  
  1746.         /* calc act */
  1747.         unit_ptr->act = (*unit_ptr->act_func) (unit_ptr);
  1748.  
  1749.         /* restore new value */
  1750.         unit_ptr->Out.output = new_output;
  1751.     }
  1752.  
  1753.     return( KRERR_NO_ERROR );
  1754. }
  1755.  
  1756.  
  1757.  
  1758. /*****************************************************************************
  1759.   FUNCTION : UPDATE_JE_Propagate 
  1760.  
  1761.   PURPOSE  : update function for JORDAN / ELMAN networks
  1762.   NOTES    :
  1763.  
  1764.   UPDATE   : 
  1765. ******************************************************************************/
  1766. krui_err  UPDATE_JE_Propagate (float *parameterArray, int NoOfParams)
  1767. {
  1768.     register struct Unit  *unit_ptr ;
  1769.     register TopoPtrArray  topo_ptr, help_ptr ;
  1770.     int      ret_code, i ;
  1771.  
  1772.  
  1773.     if (NetModified || (TopoSortID != TOPOLOGICAL_JE)){  
  1774.     /* network was modified or topologic array isn't initialized */
  1775.  
  1776.     ret_code = kr_topoCheckJE () ;
  1777.     if (ret_code != KRERR_NO_ERROR) return (ret_code) ;
  1778.  
  1779.     ret_code = kr_topoSort (TOPOLOGICAL_JE) ;
  1780.     if (ret_code != KRERR_NO_ERROR) return (ret_code) ;
  1781.  
  1782.     NetModified = FALSE ;
  1783.     }
  1784.  
  1785.     topo_ptr = topo_ptr_array ;
  1786.  
  1787.  
  1788.     /*  calculate output of input units */
  1789.  
  1790.     while ((unit_ptr = *++topo_ptr) != NULL){
  1791.     if (unit_ptr->out_func == OUT_IDENTITY)
  1792.         unit_ptr->Out.output = unit_ptr->act ;
  1793.     else
  1794.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act) ;
  1795.     }
  1796.  
  1797.  
  1798.     /* propagate hidden and output units */
  1799.  
  1800.     for (i = 0 ; i < 2 ; i++){
  1801.     while ((unit_ptr = *++topo_ptr) != NULL){
  1802.         unit_ptr->act = (*unit_ptr->act_func) (unit_ptr) ;
  1803.  
  1804.         if (unit_ptr->out_func == OUT_IDENTITY)
  1805.         unit_ptr->Out.output = unit_ptr->act ;
  1806.         else
  1807.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act) ;
  1808.     }
  1809.     }
  1810.  
  1811.  
  1812.     /* update of context units */
  1813.  
  1814.     help_ptr = topo_ptr ;
  1815.  
  1816.     while ((unit_ptr = *++help_ptr) != NULL){ 
  1817.     unit_ptr->act = (*unit_ptr->act_func) (unit_ptr) ;
  1818.     }
  1819.  
  1820.     while ((unit_ptr = *++topo_ptr) != NULL){
  1821.     if (unit_ptr->out_func == OUT_IDENTITY)
  1822.         unit_ptr->Out.output = unit_ptr->act ;
  1823.     else
  1824.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act) ;
  1825.     }
  1826.  
  1827.     return (KRERR_NO_ERROR) ;
  1828. }
  1829.  
  1830.  
  1831.  
  1832. /*****************************************************************************
  1833.   FUNCTION : UPDATE_JE_Special
  1834.  
  1835.   PURPOSE  : update function with dynamic pattern generation for JORDAN / 
  1836.              ELMAN networks
  1837.   NOTES    :
  1838.  
  1839.   UPDATE   : 
  1840. ******************************************************************************/
  1841. krui_err  UPDATE_JE_Special (float *parameterArray, int NoOfParams)
  1842. {
  1843.     register struct Unit  *unit_ptr  ;
  1844.     register TopoPtrArray  topo_ptr, help_ptr ;
  1845.     int      ret_code, i ;
  1846.  
  1847.  
  1848.     if (NetModified || (TopoSortID != TOPOLOGICAL_JE)){  
  1849.     /*  network was modified or topologic array isn't initialized */
  1850.  
  1851.     ret_code = kr_topoCheckJE () ;
  1852.     if (ret_code != KRERR_NO_ERROR) return (ret_code) ;
  1853.  
  1854.     ret_code = kr_topoSort (TOPOLOGICAL_JE) ;
  1855.     if (ret_code != KRERR_NO_ERROR) return (ret_code) ;
  1856.  
  1857.     NetModified = FALSE ;
  1858.     }
  1859.  
  1860.     if (NoOfInputUnits < NoOfOutputUnits) return (-1) ;
  1861.  
  1862.  
  1863.     /* create new input pattern from the output of input and output units */ 
  1864.  
  1865.     help_ptr = topo_ptr_array ;
  1866.     while (*++help_ptr != NULL) ; /* skip input  units */
  1867.     while (*++help_ptr != NULL) ; /* skip hidden units */
  1868.   
  1869.     topo_ptr = topo_ptr_array ;
  1870.  
  1871.     for (i = 1 ; i <= NoOfInputUnits ; i++)
  1872.     if (i <= NoOfInputUnits - NoOfOutputUnits)
  1873.         (*(topo_ptr+i))->act = (*(topo_ptr+i+NoOfOutputUnits))->Out.output;
  1874.     else
  1875.         (*(topo_ptr+i))->act = (*++help_ptr)->Out.output ;
  1876.  
  1877.     topo_ptr = topo_ptr_array ;
  1878.  
  1879.  
  1880.     /* calculate output of input units */
  1881.  
  1882.     while ((unit_ptr = *++topo_ptr) != NULL){
  1883.     if (unit_ptr->out_func == OUT_IDENTITY)
  1884.         unit_ptr->Out.output = unit_ptr->act ;
  1885.     else
  1886.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act) ;
  1887.     }
  1888.  
  1889.  
  1890.     /* propagate hidden and output units  */
  1891.  
  1892.     for (i = 0 ; i < 2 ; i++){
  1893.     while ((unit_ptr = *++topo_ptr) != NULL){
  1894.         unit_ptr->act = (*unit_ptr->act_func) (unit_ptr) ;
  1895.  
  1896.         if (unit_ptr->out_func == OUT_IDENTITY)
  1897.         unit_ptr->Out.output = unit_ptr->act ;
  1898.         else
  1899.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act) ;
  1900.     }
  1901.     }
  1902.  
  1903.  
  1904.     /* synchronous update of context units */
  1905.  
  1906.     help_ptr = topo_ptr ;
  1907.  
  1908.     while ((unit_ptr = *++help_ptr) != NULL){ 
  1909.     unit_ptr->act = (*unit_ptr->act_func) (unit_ptr) ;
  1910.     }
  1911.  
  1912.     while ((unit_ptr = *++topo_ptr) != NULL){
  1913.     if (unit_ptr->out_func == OUT_IDENTITY)
  1914.         unit_ptr->Out.output = unit_ptr->act ;
  1915.     else
  1916.         unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act) ;
  1917.     }
  1918.  
  1919.     return (KRERR_NO_ERROR) ;
  1920. }
  1921.  
  1922.  
  1923.  
  1924. /*****************************************************************************
  1925.   FUNCTION : UPDATE_syncPropagateHop
  1926.  
  1927.   PURPOSE  : synchronous propagation for Hopfield 
  1928.   RETURNS  : 
  1929.   NOTES    :
  1930.  
  1931.   UPDATE   : 
  1932. ******************************************************************************/
  1933. krui_err  UPDATE_syncPropagateHop(float *parameterArray, int NoOfParams)
  1934. {
  1935.     register struct Unit   *unit_ptr; 
  1936.     int                     unit_no;
  1937.  
  1938.     /* update unit outputs first, because the patterns set only          */
  1939.     /* the activations of the input units, and they would be overwritten */
  1940.     FOR_ALL_UNITS( unit_ptr ) {
  1941.     if UNIT_IN_USE(unit_ptr) {
  1942.         if (*unit_ptr->out_func == OUT_IDENTITY) {
  1943.         unit_ptr->Out.output = unit_ptr->act;
  1944.         }else{ /* the default way */
  1945.         unit_ptr->Out.output = (*unit_ptr->out_func)(unit_ptr->act);
  1946.         }
  1947.     }
  1948.     }
  1949.  
  1950.     /* update unit activations second */
  1951.  
  1952.     /* first non input, then input units, so function can be used for BAM too */
  1953.     FOR_ALL_UNITS( unit_ptr ){
  1954.     if (UNIT_IN_USE(unit_ptr)&&!IS_INPUT_UNIT(unit_ptr))
  1955.         unit_ptr->act  = (*unit_ptr->act_func) (unit_ptr);
  1956.     } 
  1957.  
  1958.     /* output update of non input units (for resultfile) */
  1959.     FOR_ALL_UNITS( unit_ptr ) {
  1960.     if (UNIT_IN_USE(unit_ptr) && !IS_INPUT_UNIT(unit_ptr)) {
  1961.         if (*unit_ptr->out_func == OUT_IDENTITY) { 
  1962.         unit_ptr->Out.output = unit_ptr->act;
  1963.         }else{ /* the default way */
  1964.         unit_ptr->Out.output = (*unit_ptr->out_func)(unit_ptr->act);
  1965.         }
  1966.     }
  1967.     }
  1968.  
  1969.     /* update input units */
  1970.  
  1971.     FOR_ALL_UNITS( unit_ptr ){
  1972.     if (UNIT_IN_USE(unit_ptr)&&IS_INPUT_UNIT(unit_ptr))
  1973.         unit_ptr->act  = (*unit_ptr->act_func) (unit_ptr);
  1974.     } 
  1975.  
  1976.     /* output update of input units (for resultfile) */
  1977.  
  1978.     FOR_ALL_UNITS( unit_ptr ) {
  1979.     if (UNIT_IN_USE(unit_ptr) && IS_INPUT_UNIT(unit_ptr)) {
  1980.         if (*unit_ptr->out_func == OUT_IDENTITY) { 
  1981.         unit_ptr->Out.output = unit_ptr->act;
  1982.         }else{ /* the default way */
  1983.         unit_ptr->Out.output = (*unit_ptr->out_func)(unit_ptr->act);
  1984.         }
  1985.     }
  1986.     }
  1987.  
  1988.     return( KRERR_NO_ERROR );
  1989.  
  1990.  
  1991.  
  1992. /*****************************************************************************
  1993.   FUNCTION : UPDATE_FixAct_Hop
  1994.  
  1995.   PURPOSE  : synchronous update with fixed activity
  1996.   RETURNS  : 
  1997.   NOTES    : the units updated are given the activity 1 the others 0  
  1998.  
  1999.   UPDATE   : 
  2000. ******************************************************************************/
  2001. krui_err  UPDATE_FixAct_Hop(float *parameterArray, int NoOfParams)
  2002. {
  2003.     register struct Unit   *unit_ptr; 
  2004.     FlintType               sum, aux, min;
  2005.     ACT_FUNC_DEFS    /* defines link- and site-pointer */
  2006.     register int            i;
  2007.     int                     NoOfOnes, where;
  2008.     int                     unit_no;
  2009.     struct Unit            **unitsToUpdate;
  2010.     FlintType              *netInputArray;
  2011.     short                   is_to_update;
  2012.    
  2013.  
  2014.     NoOfOnes = parameterArray[0]; /* the fixed Number of 1 */
  2015.  
  2016.     /* init netInputArray and unitsToUpdate */
  2017.     netInputArray = (FlintType *) calloc(NoOfOnes, sizeof(FlintType));
  2018.     unitsToUpdate = (struct Unit * *) calloc(NoOfOnes, sizeof( struct Unit *)); 
  2019.     for(i=0; i< NoOfOnes-1; i++) {
  2020.     unitsToUpdate[i] = NULL;
  2021.     netInputArray[i] = -9e37;
  2022.     }
  2023.  
  2024.     FOR_ALL_UNITS(unit_ptr) { 
  2025.     if UNIT_IN_USE(unit_ptr) {
  2026.         if (*unit_ptr->out_func == OUT_IDENTITY) { 
  2027.         unit_ptr->Out.output = unit_ptr->act;
  2028.         }else{/* the default way */
  2029.         unit_ptr->Out.output = (*unit_ptr->out_func)(unit_ptr->act);
  2030.         }
  2031.     }
  2032.     }
  2033.  
  2034.  
  2035.     /* find the units to update (their nr. is given by "NoOfOnes") */ 
  2036.     FOR_ALL_UNITS(unit_ptr) {
  2037.     /* get the netInput of this unit */
  2038.     sum =  0.0; aux = 0.0;
  2039.     if (GET_FIRST_UNIT_LINK( unit_ptr )){
  2040.         do
  2041.         sum += GET_WEIGHTED_OUTPUT;
  2042.         while (GET_NEXT_LINK);
  2043.     }
  2044.       
  2045.     /* get the min of netInputArray */
  2046.     min = netInputArray[0];
  2047.     where = 0;
  2048.     for(i = 1; i <= NoOfOnes - 1; i++) {
  2049.         if( netInputArray[i] < min) {
  2050.         min = netInputArray[i];
  2051.         where = i;
  2052.         }
  2053.     }
  2054.  
  2055.     /* replace it */
  2056.     if( sum > min ){
  2057.         netInputArray[where] = sum;
  2058.         unitsToUpdate[where] = unit_ptr;
  2059.     }
  2060.     }
  2061.  
  2062.     /*    update unit activations    */
  2063.     FOR_ALL_UNITS(unit_ptr){
  2064.     unit_ptr->act =  0.0;
  2065.     }
  2066.     for(i=0; i<= NoOfOnes-1; i++){
  2067.     unit_ptr = unitsToUpdate[i];
  2068.     unit_ptr->act =  1.0;
  2069.     }
  2070.  
  2071.     /* output update for resultfile */
  2072.     FOR_ALL_UNITS(unit_ptr) { 
  2073.     if UNIT_IN_USE(unit_ptr) {
  2074.         if (*unit_ptr->out_func == OUT_IDENTITY) { 
  2075.         unit_ptr->Out.output = unit_ptr->act;
  2076.         }else{/* the default way */
  2077.         unit_ptr->Out.output = (*unit_ptr->out_func)(unit_ptr->act);
  2078.         }
  2079.     }
  2080.     }
  2081.     free(netInputArray);
  2082.     free(unitsToUpdate);
  2083.   
  2084.     return( KRERR_NO_ERROR );
  2085. }
  2086.  
  2087.  
  2088. /*****************************************************************************
  2089.   FUNCTION : UPDATE_RM_Propagate
  2090.  
  2091.   PURPOSE  : 
  2092.   RETURNS  : 
  2093.   NOTES    : McClelland & Rummelhart's update rule
  2094.  
  2095.   UPDATE   : 
  2096. ******************************************************************************/
  2097. krui_err UPDATE_RM_Propagate (float *parameterArray, int NoOfParams)
  2098. {
  2099.   register struct Unit   *unit_ptr;
  2100.   int t, NoTimes; 
  2101.  
  2102.   NoTimes = parameterArray[0];
  2103.  
  2104.   for (t=0; t < NoTimes; ++t){ 
  2105.  
  2106.       /*  update unit activations */
  2107.       FOR_ALL_UNITS( unit_ptr )
  2108.       if UNIT_IN_USE( unit_ptr )
  2109.           if ( !IS_INPUT_UNIT( unit_ptr)) 
  2110.           /*  unit isn't an input unit and is in use and enabled  */
  2111.           unit_ptr->act = (*unit_ptr->act_func) (unit_ptr);
  2112.  
  2113.       /* update unit outputs  */
  2114.       FOR_ALL_UNITS( unit_ptr )
  2115.       if UNIT_IN_USE( unit_ptr )
  2116.           if (unit_ptr->out_func == OUT_IDENTITY)
  2117.           /*  identity output function: don't call output function  */
  2118.           unit_ptr->Out.output = unit_ptr->act;
  2119.           else
  2120.           /* calculate unit's output also  */
  2121.           unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  2122.   }
  2123.  
  2124.   return( KRERR_NO_ERROR );
  2125.  
  2126. }
  2127.  
  2128.  
  2129. /*#################################################
  2130.  
  2131. GROUP: User Defined Update Functions
  2132.  
  2133. #################################################*/
  2134.  
  2135.